<?php

use Illuminate\Database\Seeder;
use App\Http\Models\Admin\Permission_;
use App\Http\Models\Admin\PermissionsDetails;

class ClassifyHasPermissionsSeed extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        // if (!DB::table('PermissionsDetails')->where('id', 1)->first()) {
        //     DB::table('ClassifyPermissions')->insert(
        //         ['id' => 1, 'title' => '用户管理','parent_id'=>'0', 'rank' => '10', 'created_at' => date('Y-m-d H:i:s'),]
        //     );
        // }
        $details = array(
            array('explain' => '修改权限', 'name' => 'update power','classify'=>2),
            array('explain' => '创建权限', 'name' => 'create power','classify'=>2),
            array('explain' => '查看权限', 'name' => 'watch power','classify'=>2),
            array('explain' => '删除权限', 'name' => 'delete power','classify'=>2),

            array('explain' => '创建用户', 'name' => 'create user','classify'=>4),
            array('explain' => '修改用户', 'name' => 'update user','classify'=>4),
            array('explain' => '查看用户', 'name' => 'watch user','classify'=>4),
            array('explain' => '删除用户', 'name' => 'delete user','classify'=>4),
            array('explain' => '修改密码', 'name' => 'change_password','classify'=>4),

            array('explain' => '创建角色', 'name' => 'create roles','classify'=>3),
            array('explain' => '修改角色', 'name' => 'update roles','classify'=>3),
            array('explain' => '查看角色', 'name' => 'watch roles','classify'=>3),
            array('explain' => '删除角色', 'name' => 'delete roles','classify'=>3),
        );

        foreach ($details as $key => $value) {
            $permission = Permission_::where(array('name' => $value['name']))->first();
            
            if ($permission) {
                $permission->classify_belongsToMany()->sync($value['classify']);
            }
        }
    }
}
